#!/bin/bash

echo "========================================"
echo "项目发布清理脚本"
echo "========================================"
echo

# 获取脚本所在目录的父目录作为项目根目录
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$PROJECT_ROOT"

echo "当前目录: $(pwd)"
echo

echo "[1/6] 清理编译产物..."
if ls mcp-server/*.exe 1> /dev/null 2>&1; then
    rm -f mcp-server/*.exe
    echo "  已删除: mcp-server/*.exe"
fi
if [ -f "mcp-server/dependency-report.json" ]; then
    rm -f "mcp-server/dependency-report.json"
    echo "  已删除: dependency-report.json"
fi

echo "[2/6] 清理测试结果..."
if [ -d "mcp-server/results" ]; then
    rm -rf "mcp-server/results"
    echo "  已删除: mcp-server/results/"
fi

echo "[3/6] 清理测试工具..."
test_dirs=(
    "mcp-server/cmd/debug_storage"
    "mcp-server/cmd/search_demo"
    "mcp-server/cmd/simple_search"
    "mcp-server/cmd/vectorize_knowledge"
    "mcp-server/cmd/vectorize_knowledge_fixed"
    "mcp-server/cmd/verify_vectors"
)

for dir in "${test_dirs[@]}"; do
    if [ -d "$dir" ]; then
        rm -rf "$dir"
        echo "  已删除: $dir/"
    fi
done

echo "[4/6] 清理测试脚本..."
test_files=(
    "mcp-server/analyze_samples.go"
    "mcp-server/analyze_samples_fixed.go"
    "mcp-server/batch_test_samples.go"
    "mcp-server/test_sample.md"
    "mcp-server/test_splitter.go"
    "mcp-server/test_vectors.go"
)

for file in "${test_files[@]}"; do
    if [ -f "$file" ]; then
        rm -f "$file"
        echo "  已删除: $(basename "$file")"
    fi
done

echo "[5/6] 清理示例和演示文件..."
demo_dirs=(
    "mcp-server/examples"
    "mcp-server/demo_docs"
    "mcp-server/scripts"
    "mcp-server/docs"
)

for dir in "${demo_dirs[@]}"; do
    if [ -d "$dir" ]; then
        rm -rf "$dir"
        echo "  已删除: $dir/"
    fi
done

echo "[6/6] 清理开发文档..."
dev_docs=(
    "mcp-server/IMPLEMENTATION_SUMMARY.md"
    "mcp-server/README_VECTOR.md"
    "mcp-server/VECTORIZATION_VERIFICATION_REPORT.md"
)

for doc in "${dev_docs[@]}"; do
    if [ -f "$doc" ]; then
        rm -f "$doc"
        echo "  已删除: $(basename "$doc")"
    fi
done

echo
echo "========================================"
echo "清理完成！"
echo "========================================"
echo
echo "已清理的内容:"
echo "- 编译产物 (*.exe)"
echo "- 测试结果目录"
echo "- 测试工具目录"
echo "- 测试脚本文件"
echo "- 示例和演示文件"
echo "- 开发文档"
echo
echo "保留的核心内容:"
echo "- mcp-server/internal/ (核心模块)"
echo "- mcp-server/cmd/server/ (主服务)"
echo "- mcp-server/cmd/text-splitter/ (文本分片工具)"
echo "- mcp-server/bin/ (编译后的可执行文件)"
echo "- build/ (构建脚本)"
echo "- 配置文件和模块定义"
echo